package com.aifast.system.fd.controller;

import com.aifast.common.annotations.AiIdempotent;
import com.aifast.common.base.R;
import com.aifast.common.layui.LayuiDataTable;
import com.aifast.system.fd.entity.FdSchool;
import com.aifast.system.fd.service.FdSchoolService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import com.aifast.common.base.Controller;
/**
 * 全国高校信息 控制层
 *
 * @author fujian
 * @date 2022-08-05
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/fd/school")
public class FdSchoolController extends Controller
{

    /**
    * 视图层跳转统一调度 （统一放在viewController）
    * @param path 页面名称
    */
    @GetMapping("/fd/school/{path}")
    public String school(@PathVariable String path){
        return "fd/school/" + path;
    }

    private final FdSchoolService service;

    @GetMapping("list")
    public LayuiDataTable list() {
        return service.list(getLong("cityId"), getLong("level"), get("name"), getLong("area"), get("type"), getPage());
    }

    @AiIdempotent
    @PostMapping("add")
    public R add(@Valid FdSchool fdSchool) {
        return service.insertOrUpdate(fdSchool) ? OK() : ERROR();
    }

    @AiIdempotent
    @GetMapping("del")
    public R del() {
        return service.del(getLong("id"), get("ids")) ? OK() : ERROR();
    }

    @GetMapping("info")
    public R info() {
        return service.info(getLong("id"));
    }

}
